 /*
 * @description: 评论举报管理
 * @Author: along
 * @Date: 2019-08-24
 * @Last Modified by: along
 * @Last Modified time: 2020-08-24
 */
<template>
    <div class="container commentReport">
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <el-radio-group
                        v-model="pageType"
                        size="small"
                        @change="getPageType"
                    >
                        <el-radio-button label="user" >用户举报</el-radio-button>
                        <el-radio-button label="comment">评论举报</el-radio-button>
                    </el-radio-group>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">用户手机/ID:</p>
                    <el-input
                        v-model="formData.ID"
                        placeholder="请输入手机/ID"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">举报类型:</p>
                    <el-select
                        v-model="formData.report_type"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in reportList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"/>
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">处理结果:</p>
                    <el-select
                        v-model="formData.result"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in resultList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"/>
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">举报时间:</p>
                    <el-date-picker
                        v-model="date"
                        type="datetimerange"
                        :picker-options="pickerOptions()"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        align="right"
                        size="small"
                        @change="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        搜索
                    </el-button>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="commentReport"
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="id"
                label="举报编号"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            />
            <el-table-column
                prop="student.student_no"
                label="用户编号"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            />
            <el-table-column
                prop="student.true_name"
                label="用户名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="student.real_name"
                label="真实姓名"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="student.phone"
                label="手机号"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            />
            <el-table-column
                prop="school"
                label="用户学校"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="content"
                label="评论内容"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="images"
                label="评论图片"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    <p
                        v-if="scope.row.images.length > 0"
                        class="cursor-font"
                        @click="fnShowPreview(scope.row.images, 0)"
                    >
                        查看({{ scope.row.images.length }})
                    </p>
                    <p v-else>
                        --
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                prop="type"
                label="举报类型"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    <p>
                        {{ scope.row.type | filterType }}
                    </p>
                    <p v-if="scope.row.type == 9">
                        {{ '--' }}
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                prop="reason"
                label="举报理由"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="status"
                label="状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    <p v-if="scope.row.status == 1">正常</p>
                    <p v-if="scope.row.status == 0">下架</p>
                </template>
            </el-table-column>
            <el-table-column
                prop="result"
                label="处理结果"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    <p v-if="scope.row.result == 1">已受理</p>
                    <p v-if="scope.row.result == 0">未处理</p>
                    <p v-if="scope.row.result == -1">已驳回</p>
                </template>
            </el-table-column>
            <el-table-column
                prop="create_time"
                label="举报时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            >
                <template slot-scope="scope">
                    {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                fixed="right"
            >
                <template slot-scope="scope">
                    <div class="button-list">
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnShelf(scope.row, 1)"
                            :disabled="scope.row.result !== 0"
                        >
                            受理
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnShelf(scope.row, 0)"
                            :disabled="scope.row.result !== 0"
                        >
                            驳回
                        </el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

        <!-- 图片预览 -->
        <img-preview ref="preview" />
    </div>
</template>

<script>
import imgPreview from '@/components/common/img-preview';
import { back } from '@/mixin/back';
import { getDate } from '@/assets/js/utils';
export default {
    mixins: [back],
    components: {
        imgPreview
    },
    data () {
        return {
            pageType: 'comment',
            formData: {
                ID: '',
                report_type: '',
                date: [],
                result: ''
            },
            date: [],
            reportList: [{value: '',label: '全部'},{value: 1,label: '垃圾广告'},{value: 2,label: '恶意辱骂'},{value: 3,label: '色情低俗'},{value: 4,label: '抄袭他人'},{value: 5,label: '违法违规'},{value: 6,label: '涉嫌诈骗'},{value: 7,label: '虚假谣言'},{value: 8,label: '侵犯隐私'},{value: 0,label: '其他'}],
            resultList: [{value: '',label: '全部'},{value: 0,label: '未处理'},{value: 1,label: '已受理'},{value: -1,label: '已驳回'},],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            filterData: {
                sort_field: 0,
                sort_type: 1
            },
            tableData: [],
            authResult: {}
        };
    },
    filters: {
        filterType (val) {
            if(val == 1) {
                return '垃圾广告';
            } else if (val == 2) {
                return '恶意辱骂';
            } else if (val == 3) {
                return '色情低俗';
            } else if (val == 4) {
                return '抄袭他人';
            } else if (val == 5) {
                return '违法违规';
            } else if (val == 6) {
                return '涉嫌诈骗';
            } else if (val == 7) {
                return '虚假谣言';
            } else if (val == 8) {
                return '侵犯隐私';
            } else if (val == 0) {
                return '其他';
            } else {
                return '--';
            }
        }
    },
    computed: {},
    watch: {},
    mounted () {
        this.$store.commit('SET_HEADER', [{ title: "APP后台"},{title: '社交'},{title: '夸夸我的大学'},{title: '评论举报管理'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },
    methods: {
        /**
         * @description 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/social_schoolpraise_report%5Cget_list', {
                page_id: page || this.page.now_page,
                keyword_student_id: this.formData.ID,
                type: this.formData.report_type,
                create_start_time: this.date === null ? '' : (this.date.length == 0 ? '' : getDate(new Date(this.date[0]))),
                create_end_time: this.date === null ? '' : (this.date.length == 0 ? '' : getDate(new Date(this.date[1]))),
                result: this.formData.result
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * @description 页面切换
         */
        getPageType (event) {
            if(event == 'user') {
                this.$router.push({
                    name: 'SocialReport'
                });
            } else {
                return false;
            }
        },

        /**
         * @description 下架
         */
        fnShelf (row, type) {
            if(!this.authResult.auth_verfy) {
                this.$notify({
                    title: '提示',
                    message: '此权限仅限管理员',
                    type: 'warning',
                    duration: 2000
                });
                return;
            }

            if(!type) {
                this.$confirm('是否要驳回此条举报', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$post('/student/social_schoolpraise_report%5Cverify',{
                        id: row.id,
                        result: -1
                    },resp=>{
                        if (resp.code == 1) {
                            this.getTableData();
                            this.$notify({
                                title: '提示',
                                message: '操作成功',
                                type: 'success',
                                duration: 2000
                            });
                        } else if (resp.code == 0) {
                            this.$notify({
                                title: '提示',
                                message: resp.msg,
                                type: 'warning',
                                duration: 2000
                            });
                        }
                    });
                });
            }

            if(type) {
                this.$confirm('是否要受理此条举报', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$post('/student/social_schoolpraise_report%5Cverify',{
                        id: row.id,
                        result: 1
                    },resp=>{
                        if (resp.code == 1) {
                            this.getTableData();
                            this.$notify({
                                title: '提示',
                                message: '操作成功',
                                type: 'success',
                                duration: 2000
                            });
                        } else if (resp.code == 0) {
                            this.$notify({
                                title: '提示',
                                message: resp.msg,
                                type: 'warning',
                                duration: 2000
                            });
                        }
                    });
                });
            }
        },

        /**
         * @description 时间处理
         */
        pickerOptions () {
            return {
                shortcuts : [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            };
        },

        /**
         * @description 查看图片
         * @param   {String}    images    单图预览
         * @param   {Array}     images     多图预览
         */
        fnShowPreview(images) {
            if(images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images);
            } else {
                this.$notify({
                    title: '提示',
                    message: '图片类型错误',
                    type: 'warning',
                    duration: 2000
                });
            }
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 5px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
    .button-list {
        display: flex;
        flex-direction: column;
        align-items: center;
        .el-button {
            margin-left: 0 !important;
            padding: 5px 0;
        }
    }
</style>
<style lang="less">
    .commentReport{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
    }
</style>